//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Web.UI.WebControls;
using CommunityServer.Components;
using CommunityServer.ControlPanel.Controls;
using CommunityServer.ControlPanel.UI;

namespace CommunityServer.ControlPanel.Settings
{
	/// <summary>
	/// Summary description for ContactInfo.
	/// </summary>
	public class ContactInfo : BaseSettingsPage
	{
		#region Members

		protected TextBox AdminEmailAddress;
		protected TextBox CompanyName;
		protected TextBox CompanyEmailAddress;
		protected TextBox CompanyFaxNumber;
		protected TextBox CompanyAddress;
		protected RegularExpressionValidator RegularExpressionValidator1;
		protected RegularExpressionValidator RegularExpressionValidator2;

		protected StatusMessage Status;
		protected CommunityServer.ControlPanel.Controls.ControlPanelSelectedNavigation SelectedNavigation1;
		protected CommunityServer.ControlPanel.Controls.ResourceControl RegionTitle;
		protected CommunityServer.Controls.MPContent DescriptionRegion;
		protected CommunityServer.ControlPanel.Controls.HelpIcon Helpicon10;
		protected CommunityServer.ControlPanel.Controls.ResourceControl ResourceControl29;
		protected CommunityServer.ControlPanel.Controls.HelpIcon Helpicon1;
		protected CommunityServer.ControlPanel.Controls.ResourceControl ResourceControl32;
		protected CommunityServer.ControlPanel.Controls.HelpIcon Helpicon2;
		protected CommunityServer.ControlPanel.Controls.ResourceControl ResourceControl34;
		protected CommunityServer.ControlPanel.Controls.HelpIcon Helpicon3;
		protected CommunityServer.ControlPanel.Controls.ResourceControl ResourceControl37;
		protected CommunityServer.ControlPanel.Controls.HelpIcon Helpicon4;
		protected CommunityServer.ControlPanel.Controls.ResourceControl ResourceControl39;
		protected CommunityServer.Controls.MPContent TaskRegion;
		protected CommunityServer.Controls.MPContainer MPContainer;
		protected ResourceLinkButton SaveButton;

		#endregion

		override protected void OnInit(EventArgs e)
		{

			this.SaveButton.Click += new EventHandler(SaveButton_Click);
			this.Load += new EventHandler(this.Page_Load);

			base.OnInit(e);
		}


		private void Page_Load(object sender, EventArgs e)
		{
			if ( !Page.IsPostBack ) 
			{
				this.Bind();
			}
		}


		protected void Bind()
		{
			SiteSettings settings = CSContext.Current.SiteSettings;
			Status.Visible = false;
			this.SaveButton.Text = ResourceManager.GetString( "Save" );

			AdminEmailAddress.Text = settings.AdminEmailAddress;
			CompanyName.Text = settings.CompanyName;
			CompanyEmailAddress.Text = settings.CompanyContactUs;
			CompanyFaxNumber.Text = settings.CompanyFaxNumber;
			CompanyAddress.Text = settings.CompanyAddress;

		}

		private void SaveButton_Click(object sender, EventArgs e) 
		{
			SiteSettings settings = CSContext.Current.SiteSettings;

			SaveSettings( settings );

			if(Page.IsValid)
			{
				Status.Success = true;
				Status.ResourceName = "Admin_SiteSettings_StatusSuccess";

				DataBind();
			}
			else
			{
				Status.Success = false;
				Status.ResourceName = "Admin_SiteSettings_StatusFailed";
			}

			Status.Visible = true;
		}

		private void InitializeComponent()
		{
		
		}


		protected virtual void SaveSettings( SiteSettings settings ) 
		{

			settings.AdminEmailAddress = AdminEmailAddress.Text;
			settings.CompanyName = CompanyName.Text;
			settings.CompanyContactUs = CompanyEmailAddress.Text;
			settings.CompanyFaxNumber = CompanyFaxNumber.Text;
			settings.CompanyAddress = CompanyAddress.Text;

			if(Page.IsValid)
				SiteSettingsManager.Save(settings);

		}

	}
}
